package com.ssm.icc.card.dao.mapper.equipmentCard;

import com.github.pagehelper.PageInfo;
import com.ssm.icc.card.dao.model.equipmentCard.EquipmentCard;
import com.ssm.upms.dao.mapper.ssm.LzDao;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* 设备、门禁卡关联管理 Dao
* @author GaoXiang
* @version 1.0
*/
@Repository
public class EquipmentCardDao extends LzDao<EquipmentCard> {



    /**
    * 保存数据
    * @param equipmentCard 实体对象
    * @return 实体id
    * @throws Exception 数据保存异常
    */
    public Integer insert(EquipmentCard equipmentCard) throws Exception {
        return insert("EquipmentCardMapper.insert",equipmentCard);
    }

    /**
    * 根据 id 修改
    * @param equipmentCard 带id的实体对象
    * @return 受影响的行数
    * @throws Exception 数据修改异常
    */
    public Integer updateById(EquipmentCard equipmentCard) throws Exception {
        return update("EquipmentCardMapper.updateById",equipmentCard);
    }

    /**
    * 根据 id 删除
    * @param id 数据id
    * @return 受影响的行数
    * @throws Exception 数据删除异常
    */
    public Integer deleteById(String id) throws Exception {
        return delete("EquipmentCardMapper.deleteById",id);
    }

    /**
    * 根据 id 查找
    * @param id 实体id
    * @return 实体
    */
    public EquipmentCard selectById(String id) {
        return selectOne("EquipmentCardMapper.selectById",id);
    }

    /**
    * 根据 id 批量删除
    * @param ids 要删除的id
    * @return 影响的行数
    * @throws Exception 数据删除异常
    */
    public Integer deleteByIds(List<String> ids) throws Exception {
        return delete("EquipmentCardMapper.deleteByIds",ids);
    }

    /**
    * 查询列表
    * @param map 参数
    * @return 列表
    */
    public PageInfo<EquipmentCard> list(Map map) {
        return list("EquipmentCardMapper.list",map);
    }

    /**
    * 查询列表 带分页
    * @param map 参数
    * @param page 页码
    * @param size 每页大小
    * @return 列表
    */
    public PageInfo<EquipmentCard> list(Map map, int page, int size) {
        return list("EquipmentCardMapper.list",map,new RowBounds(page,size));
    }


    /**
     * 根据设备ID 查询门禁卡ID
     * @param equipmentId 设备ID
     * @return 列表
     */
    public List<EquipmentCard> findCardId(String equipmentId) {
        return arrayList("EquipmentCardMapper.findCardId",equipmentId);
    }

    public Integer deleteByCardId(String cardId) throws Exception {
        return delete("EquipmentCardMapper.deleteByCardId",cardId);
    }

    /**
     * 根据门禁卡id 查询所有绑定的相关设备 和房屋
     * @param cardId  门禁卡id
     * @return
     */
    public List<EquipmentCard> selectByCardId(String cardId) {
        return arrayList("EquipmentCardMapper.selectByCardId",cardId);
    }

    /**
     * @param equipmentCard
     * @return 受影响的行数
     * @throws Exception 数据删除异常
     */
    public Integer delRoomIdByCard(EquipmentCard equipmentCard) throws Exception {
        return delete("EquipmentCardMapper.delRoomIdByCard",equipmentCard);
    }


    /**
     * 根据类型查询
     * @param map 类型
     * @return 列表
     */
 public PageInfo<EquipmentCard> cardList(Map map, int page, int size){
        return   list("EquipmentCardMapper.cardList",map,new RowBounds(page,size));
 }


 public List<EquipmentCard> selectByUserId(String userId){ return  arrayList("EquipmentCardMapper.selectByUserId",userId);}

    /**
     * 根据门禁卡id 查询用户id
     * @param cardId  门禁卡id
     * @return
     */
    public EquipmentCard selectUserId(String cardId) {
        return selectOne("EquipmentCardMapper.selectUserId",cardId);
    }

    public List<EquipmentCard> selectByCard(String cardId) {
        return arrayList("EquipmentCardMapper.selectByCard" ,cardId);
    }

    /**
     * 根据设备id 删除相关信息
     * @param id
     * @return
     * @throws Exception
     */
    public Integer deleteByEquipmentId(String id) throws Exception {
        return delete("EquipmentCardMapper.deleteByEquipmentId",id);
    }

    /**
     * 根据room_id和user_id删除门禁卡和设备的关联表
     * @param equipmentCard 实体
     * @return 受影响的行数
     * @throws Exception 数据删除异常
     */
    public Integer delUserRoom(EquipmentCard equipmentCard) throws Exception {
        return  delete("EquipmentCardMapper.delUserRoom",equipmentCard);
    }
}
